function output = hm_probs(pms,dt,rn)

% pms is a 6x1 vector of parameters, pms = (alpha,beta,kappa,delta,gamma,lambda),
% or a 7x1 vector of parameters if rn=2 pms = (alpha,beta,kappa,delta,gamma,lambda,r) 
% dt contains the data
% rn indicates whether or not risk neutrality is assumed (rn=0 uses the 
% lottery choices for r, rn=1 implies risk neutrality and rn=2 uses r from pms(7))

lot = dt(1,10);     % lottery chosen   
id = dt(1,11);      % id number (session#*100+subjectid)
    
risky2=[4.71 2.95 1.19 0.77 0.32 -0.13];    % rho parameters from lotteries in the first session
risky=[1.61 1 0.39 0.25 0.08 -0.09];        % rho parameters from lotteries in all other sessions

alpha = pms(1); beta = pms(2); kappa = pms(3); delta=pms(4); gamma=pms(5); lambda=pms(6); 
    
if rn==2
    rho=pms(7);
elseif rn==0
    if id<200
        rho=risky2(lot);
    end
    if id>=200
        rho=risky(lot);
    end    
else
    rho=0;
end

[n,m] = size(dt);  

eu=zeros(1,8);
eu2=zeros(1,4);
eu3=zeros(1,4);
probs=zeros(n,8);

nonan = 0;

for i = 1:n
    
    theta = dt(i,1:4);  % payoff parameters
    prefs = [alpha beta kappa delta gamma]; % preference parameters
    y = dt(i,5:7);      % beliefs 
    game = dt(i,9);     % 1=spd or 2=ug or 3=tg
       
    while nonan==0
        
    if game==1
        for str = 1:8
            eu(str) = eu_spd(prefs,rho,theta,str,y);
        end        
        probs(i,1:8)=exp((1/lambda)*eu)/sum(exp((1/lambda)*eu));
    end

    if game==2
        for str = 1:4
            eu2(str) = eu_ug(prefs,rho,theta,str,y);
        end
        probs(i,1:4)=exp((1/lambda)*eu2)/sum(exp((1/lambda)*eu2));        
    end
    
    if game==3
        for str = 1:4
            eu3(str) = eu_tg(prefs,rho,theta,str,y);
        end 
        probs(i,1:4)=exp((1/lambda)*eu3)/sum(exp((1/lambda)*eu3));
    end
    
    contains_nan = sum(isnan(probs));
    
    if contains_nan>0
        lambda = lambda*10;
        nonan = 0;
    else
        nonan = 1;
    end
    
    end
end

output = probs;